package com.gzgs.controller;

import com.gzgs.domain.Permission;
import com.gzgs.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 资源权限控制器
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {

    /**
     * 查询所有的权限
     */
    @Autowired
    private PermissionService permissionService;
    @RequestMapping("/findAll")
    public ModelAndView findAll() throws Exception{
        ModelAndView mv=new ModelAndView();
        List<Permission> permissionList=permissionService.findAll();
        mv.addObject("permissionList",permissionList);
        mv.setViewName("permission-list");
        return mv;
    }

    /**
     * 新建权限
     */
    @RequestMapping("/save.do")
    public String savePermission(Permission permission)throws Exception{
        permissionService.savePermission(permission);
        return "redirect:findAll.do";
    }

    /**
     * 查询单个权限
     */
    @RequestMapping("/findById.do")
    public ModelAndView findById(String id) throws Exception {
        ModelAndView mv=new ModelAndView();
        Permission permission=permissionService.findById(id);
        mv.addObject("permission",permission);
        mv.setViewName("permission-show");
        return mv;
    }
    /**
     * 删除权限
     */
    @RequestMapping("/deletePermission.do")
    public String deletePermission(String  id) throws Exception {

        permissionService.deletePermission(id);
        return "redirect:findAll.do";

    }
}
